/*
	Copyright (c) [2019] [一只程序缘 jiezhuo]
	[https://gitee.com/jiezhuonew/oledlib] is licensed under the Mulan PSL v1.
	You can use this software according to the terms and conditions of the Mulan PSL v1.
	You may obtain a copy of Mulan PSL v1 at:
		http://license.coscl.org.cn/MulanPSL
	THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
	PURPOSE.
	See the Mulan PSL v1 for more details.

	图形库原理:其实就是对一个数组进行操作,数组操作完成之后,直接将整个
	数组刷新到屏幕上
	因此此c文件用于配置oled底层 用于单片机与oled的直接且唯一通信

	移植此图形库主要完善单片机与OLED的通信:
	SPI_Configuration() 	配置通信引脚
	WriteCmd()      		写命令
	WriteDat()      		写数据
	OledTimeMsFunc()  oled_config中的函数 为系统提供时基
	此例程仅演示SPI通信方式 需要更改其他通信方式请在[oled_config.h]修改
*/


#include "stm32f1xx_hal.h"
#include "oled_driver.h"
#include "delay.h"

#if (TRANSFER_METHOD == HW_IIC)	//1.硬件IIC

	//I2C_Configuration，初始化硬件IIC引脚
	void I2C_Configuration(void)
	{
		//已经通过CubeMX实现IIC配置
	}

	/**
		 @brief  I2C_WriteByte，向OLED寄存器地址写一个byte的数据
		 @param  addr：寄存器地址
						 data：要写入的数据
		 @retval 无
	*/
	I2C_HandleTypeDef  oledlib_var_i2c;							//定义iic控制句柄
	void oled_set_oledlib_i2c_handle(I2C_HandleTypeDef ref_value)
	{
		oledlib_var_i2c = ref_value;
	}
	void I2C_WriteByte(uint8_t addr, uint8_t data)
	{
		//HAL_I2C_Mem_Write(&oledlib_var_i2c, 0x78, addr, I2C_MEMADD_SIZE_8BIT, &data,1,100);
	}

	void WriteCmd(unsigned char cmd)//写命令
	{
		//uint8_t *pData;
    //pData = &cmd;
		//HAL_I2C_Mem_Write(&oledlib_var_i2c, 0x78, 0x00,I2C_MEMADD_SIZE_8BIT,pData,1,100);
		//I2C_WriteByte(0x00, cmd);
	}

	void WriteDat(unsigned char dat)//写数据
	{
		I2C_WriteByte(0x40, dat);
	}

/////////////////////////////////////////////////硬件IIC完成 2022.1.4///////////////////////

#endif //(TRANSFER_METHOD ==HW_IIC)


void OLED_Init(void)
{
	//在这里添加oled初始化驱动函数
}

void OLED_ON(void)
{
	WriteCmd(0X8D);  //设置电荷泵
	WriteCmd(0X14);  //开启电荷泵
	WriteCmd(0XAF);  //OLED唤醒
}

void OLED_OFF(void)
{
	WriteCmd(0X8D);  //设置电荷泵
	WriteCmd(0X10);  //关闭电荷泵
	WriteCmd(0XAE);  //OLED休眠
}

void OLED_FILL(unsigned char BMP[])
{
	uint8_t i, j;
	unsigned char *p;
	p = BMP;

	for (i = 0; i < 8; i++)
	{
		WriteCmd(0xb0 + i); //page0-page1
		WriteCmd(0x00);   //low column start address
		WriteCmd(0x10);

		for (j = 0; j < 128; j++)
		{
			WriteDat(*p++);
		}
	}
}



